# 使用 OpenWRT 基础镜像
FROM sulinggg/openwrt:latest

# 安装必要的依赖
RUN opkg update && opkg install \
    libnl \
    libnl-route \
    tc \
    ip \
    iptables-mod-extra \
    kmod-sched \
    kmod-ifb \
    luci \
    luci-base \
    luci-compat \
    bash \
    coreutils-timeout

# 创建必要的目录
RUN mkdir -p /usr/lib/netflow/models \
    /usr/lib/netflow/bin \
    /etc/netflow \
    /var/log/netflow \
    /var/run/netflow \
    /www/netflow

# 复制系统文件
COPY src/bandwidth_manager.c /usr/lib/netflow/src/
COPY src/priority_scheduler.c /usr/lib/netflow/src/
COPY models/*.lua /usr/lib/netflow/models/
COPY etc/netflow.conf /etc/netflow/
COPY views/*.htm /www/netflow/

# 编译源代码
RUN gcc -o /usr/lib/netflow/bin/bandwidth_manager /usr/lib/netflow/src/bandwidth_manager.c -lm -lpthread
RUN gcc -o /usr/lib/netflow/bin/priority_scheduler /usr/lib/netflow/src/priority_scheduler.c -lm -lpthread

# 配置服务启动脚本
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# 暴露Web管理界面端口
EXPOSE 80

# 设置入口点
ENTRYPOINT ["/entrypoint.sh"]